package com.wz.leetcode.string;

public class CompareVersion_165 {
    public static int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int n = v1.length;
        int m = v2.length;
        int i = 0;
        int j = 0;
        while (i < n || j < m) {
            int a = 0, b = 0;
            if (i < n) {
                a = Integer.parseInt(v1[i++]);
            }
            if (j < m) {
                b = Integer.parseInt(v2[j++]);
            }
            if (a != b) {
                return a > b ? 1 : -1;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(compareVersion("1.01", "1.001"));
        System.out.println(compareVersion("1.0", "1.0.0"));
        System.out.println(compareVersion("0.1", "1.1"));
    }
}
